/*
 * Copyright (c) 2012, marco.tamburelli@gmail.com
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are those
 * of the authors and should not be interpreted as representing official policies, 
 * either expressed or implied, of the CometMI Project.
 */
package org.cometmi.gwt.server.events;

import org.cometmi.gwt.shared.MiQueue;
import org.cometmi.gwt.shared.MiQueuePool;
import org.cometmi.gwt.shared.exceptions.NameParseException;
import org.cometmi.gwt.shared.exceptions.NotAllowedQueueException;

/**
 * This is a queue event. Such events are normally fired when a queue is just
 * created or just destroyed.
 * 
 * @author marco.tamburelli@gmail.com
 */
public interface QueueEvent
{
	/**
	 * This method returns the event source queue. The source queue can be:
	 * 
	 * 1. the queue triggering the event through a defined
	 * {@link QueueEventHandler}.
	 * 
	 * 2. the target queue of a method invocation request, when a client is
	 * polling.
	 * 
	 * @return The requested queue.
	 * @throws NotAllowedQueueException If the queue, during the event creation,
	 *         was not any longer available. This normally shouldn't happen,
	 *         anyway in very improbable cases could happen when from an
	 *         {@link MiEvent} client code attempt to get the target event of a
	 *         queue while it is disposing.
	 * @throws NameParseException
	 */
	MiQueue getSourceQueue() throws NotAllowedQueueException;

	/**
	 * The method returns a queue pool.
	 * 
	 * @param queueExpression The expression of the queue group. Note that the
	 *        expression must identify a pool: must be of the form
	 *        <code>org.test.*</code>
	 * @return The requested queue pool.
	 * @throws NameParseException In case the queue expression is not a valid
	 *         one.
	 */
	MiQueuePool getQueuePool(String queueExpression) throws NameParseException;

	/**
	 * The method returns a queue.
	 * 
	 * @param queueName The name of the queue.
	 * @return The requested queue
	 * @throws NameParseException In case the queue expression is not a valid
	 *         one.
	 * @throws NotAllowedQueueException If the queue is not any longer
	 *         available, e.g. has been removed while current thread was
	 *         requesting it.
	 */
	MiQueue getQueue(String queueName) throws NameParseException, NotAllowedQueueException;

	/**
	 * This method returns <code>true</code> if the query with provided name has
	 * been created and it's active.
	 * 
	 * @param queueName The name of a query.
	 * @return <code>true</code> or <code>false</code>.
	 * @throws NameParseException In case the queue name is not valid.
	 */
	boolean isQueueAlive(String queueName) throws NameParseException;
}
